var http = require("../../utils/http.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        roomInfo: [],
        total: 0,
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        wx.request({
            url: 'https://sign.jasonandjay.com/broadcast/room',
            success: (res)=>{
                console.log('res...', res);
                if (res.data.data.errcode === 0){
                    this.setData({
                        roomInfo: res.data.data.room_info.sort((a,b)=>b.roomid-a.roomid).map(item=>{
                            return {...item, 
                                start_time: this.formatTime(item.start_time), 
                                end_time: this.formatTime(item.end_time)
                            }
                        }),
                        total: res.data.data.total
                    })
                }
            }
        })
    },

    formatTime(str, showDate=true){
        let date = new Date(str*1000);
        let year = date.getFullYear(),
            month = String(date.getMonth() + 1).padStart(2, '0'),
            day = String(date.getDate()).padStart(2, '0'),
            hour = String(date.getHours()).padStart(2, '0'),
            min = String(date.getMinutes()).padStart(2, '0'),
            sec = String(date.getSeconds()).padStart(2, '0');
        
        return showDate?`${month}-${day} ${hour}:${min}`: `${hour}:${min}`
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})